Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the ability to inject authenticators. #2311

Merged
merged 2 commits into from
Mar 24, 2025

Conversation

brendandburns
Copy link
Contributor

Fixes #2263

@k8s-ci-robot k8s-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Mar 10, 2025
Copy link
Contributor

@cjihrig cjihrig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This LGTM. Just one optional comment. If you don't want to address it, I'm fine with merging as is.

@@ -65,6 +65,12 @@ export class KubeConfig implements SecurityAuthentication {
new OpenIDConnectAuth(),
];

// Optionally add additional external authenticators, you must do this
// before you load a kubeconfig file that references them.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think it is worth adding a test that intentionally does not do this (if for no other reason than knowing if it accidentally changes)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this can ever change, because the kubeconfig file references the authenticator as part of the YAML file, so if we don't know about the authenticator because it hasn't been registered when we load the kubeconfig, there's no way that we can link the authenticator requested in the file to the kubeconfig.

So while we could add a test, I'm not sure it would ever break.

src/config.ts Outdated
// Optionally add additional external authenticators, you must do this
// before you load a kubeconfig file that references them.
public static addAuthenticator(authenticator: Authenticator): void {
this.authenticators.push(authenticator);
Copy link
Contributor

@davidgamero davidgamero Mar 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i may be misunderstanding typescript classes here, but is the intended use here to add them to all existing KubeConfig objects since the authenticators property is static?

also, could we avoid the loading order issue by adding an optional parameter for an array of authenticators to the constructor instead? that way the authenticators must be added prior to loading a config

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm ok with this, but I also think it makes it a little more complicated. I wanted the authenticators to be able to self-register just by being import-ed which requires the static registration. @cjihrig wdyt?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing to note is that the authenticators are already static, so I think making this method static aligns well with the current setup.

I don't personally see a ton of upside to self-registering via import - my understanding is that it would mean calling KubeConfig.addAuthenticator() inside the import instead of in the code managing the KubeConfig instance.

Given the choice between static and per-instance custom authenticators, I think per-instance is likely to have less surprising behavior. For example, in the test added in this PR, wouldn't CustomAuthenticator be included in every subsequent test?

@brendandburns
Copy link
Contributor Author

Ok, I switched this to custom authenticators that are local to the KubeConfig instance.

Please take another look.

@cjihrig
Copy link
Contributor

cjihrig commented Mar 21, 2025

LGTM. I'll give @davidgamero a chance to weigh in before merging.

Copy link
Contributor

@cjihrig cjihrig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 24, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: anandfresh, brendandburns, cjihrig

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [brendandburns,cjihrig]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot merged commit c7286bc into kubernetes-client:main Mar 24, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can the ability to customize Authenticators be opened up?
5 participants